﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;


namespace Movie.DAL
{
   public  class sqlHelper2
    {
       public static string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;

       public static SqlDataReader ExcuteReader(string sql, SqlParameter[] paras = null)
       {


           SqlConnection conn = new SqlConnection(constr);

           conn.Open();

           SqlCommand cmd = new SqlCommand(sql, conn);

           //判断是否带有参数
           if (paras != null)
           {
               //添加参数
               foreach (var item in paras)
               {
                   cmd.Parameters.Add(item);
               }
           }

           SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);

           return reader;
       }

       public static int ExecuteNonQuery(string sql, SqlParameter[] paras = null) 
       {
           SqlConnection conn = new SqlConnection(constr);

           conn.Open();

           SqlCommand cmd = new SqlCommand(sql, conn);

           //判断是否带有参数
           if (paras != null)
           {
               //添加参数
               foreach (var item in paras)
               {
                   cmd.Parameters.Add(item);
               }
           }
          int count= cmd.ExecuteNonQuery();

          return count;
       }
     
    }
}
